const Sequelize = require('sequelize');
module.exports = function(sequelize, DataTypes) {
  return sequelize.define('Product', {
    id: {
      autoIncrement: true,
      type: DataTypes.INTEGER,
      allowNull: false,
      primaryKey: true,
      comment: "产品ID（主键）"
    },
    name: {
      type: DataTypes.STRING(255),
      allowNull: false,
      comment: "产品名称"
    },
    price: {
      type: DataTypes.DECIMAL(10,2),
      allowNull: false,
      comment: "产品价格"
    },
    stock: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: "库存数量"
    },
    description: {
      type: DataTypes.TEXT,
      allowNull: true,
      comment: "产品描述"
    },
    status: {
      type: DataTypes.TINYINT,
      allowNull: false,
      defaultValue: 1,
      comment: "状态（1：在售，0：下架）"
    }
  }, {
    sequelize,
    tableName: 'product',
    timestamps: true,
    indexes: [
      {
        name: "PRIMARY",
        unique: true,
        using: "BTREE",
        fields: [
          { name: "id" },
        ]
      },
      {
        name: "idx_product_status",
        using: "BTREE",
        fields: [
          { name: "status" },
        ]
      },
    ]
  });
};
